#include "myday.h"

QList<myDay*> MYDAYLIST;

myDay::myDay()
{
    iDayOfMonth = 0;
    iDayOfWeek = 0;
    iDayType = DATESET_NONE;
    iRow = 0;
    iCol = 0;
    iDayType = 0;
    nameDayWorkList.clear();
    nameNightWorkList.clear();
    nameDayNoWorkList.clear();
    nameNightNoWorkList.clear();
}

int myDay::GetDayOfMonth(void)
{
    return this->iDayOfMonth;
}

void myDay::SetDayOfMonth(int day)
{
    this->iDayOfMonth = day;
    return;
}

int myDay::GetDayOfWeek(void)
{
    return this->iDayOfWeek;
}

void myDay::SetDayOfWeek(int day)
{
    this->iDayOfWeek = day;
    return;
}

int myDay::GetRow(void)
{
    return this->iRow;
}

void myDay::SetRow(int row)
{
    this->iRow = row;
    return;
}

int myDay::GetCol(void)
{
    return this->iCol;
}

void myDay::SetCol(int col)
{
    this->iCol = col;
    return;
}

int myDay::GetDayType(void)
{
    return this->iDayType;
}

void myDay::SetDayType(int type)
{
    if(type > DATESET_HOLIDAY_AND_SPECIFYDAY || type < DATESET_WORKDAY)
        type = DATESET_WORKDAY;
    this->iDayType = type;
    return;
}

int myDay::getWorkType() const
{
    return iWorkType;
}

void myDay::setWorkType(int newWorkType)
{
    iWorkType = newWorkType;
}

const QStringList &myDay::getMemberList(int type) const
{
    if(DATESET_DAYWORK == type)
        return nameDayWorkList;
    else if(DATESET_NIGHTWORK == type)
        return nameNightWorkList;
    else if(DATESET_NODAYWORK == type)
        return nameDayNoWorkList;
    else if(DATESET_NONIGHTWORK == type)
        return nameNightNoWorkList;
    else{
        QLOG_WARN() << "error worktype:" << type;
        return nameDayWorkList;
    }

}

void myDay::setMemberList(const QStringList &newNameList, int type)
{
    if(DATESET_DAYWORK == type){
        nameDayWorkList = newNameList;
        uniqueMember(nameDayWorkList, nameDayNoWorkList);
        uniqueMember(nameDayWorkList, nameNightWorkList);
    }
    else if(DATESET_NIGHTWORK == type){
        nameNightWorkList = newNameList;
        uniqueMember(nameNightWorkList, nameNightNoWorkList);
        uniqueMember(nameNightWorkList, nameDayWorkList);
    }

    else if(DATESET_NODAYWORK == type){
        nameDayNoWorkList = newNameList;
        uniqueMember(nameDayNoWorkList, nameDayWorkList);
    }

    else if(DATESET_NONIGHTWORK == type){
        nameNightNoWorkList = newNameList;
        uniqueMember(nameNightNoWorkList, nameNightWorkList);
    }
    else
        QLOG_WARN() << "error worktype:" << type;

    return;
}

// 如果srcList 存在dstList的同名字符串，那么就删除dstList中的字符串
void myDay::uniqueMember(QStringList srcList, QStringList & dstList)
{

    for(int i = 0; i < srcList.count(); i++){
        int index = dstList.indexOf(srcList.at(i));
        if(-1 != index)     dstList.removeAt(index);
    }

    return;
}

int myDay::getNeedNightWorkCount() const
{
    return needNightWorkCount;
}

void myDay::setNeedNightWorkCount(int newNeedNightWorkCount)
{
    needNightWorkCount = newNeedNightWorkCount;
}

int myDay::getNeedDayWorkCount() const
{
    return needDayWorkCount;
}

void myDay::setNeedDayWorkCount(int newNeedDayWorkCount)
{
    needDayWorkCount = newNeedDayWorkCount;
}

int myDay::getMonth() const
{
    return iMonth;
}

void myDay::setMonth(int newMonth)
{
    iMonth = newMonth;
    return;
}

void myDay::stringlistAppend(int type, const QString &name)
{
    if(DATESET_DAYWORK == type){
        nameDayWorkList.append(name);
        uniqueMember(nameDayWorkList, nameDayNoWorkList);
        uniqueMember(nameDayWorkList, nameNightWorkList);
    }
    else if(DATESET_NIGHTWORK == type){
        nameNightWorkList.append(name);
        uniqueMember(nameNightWorkList, nameNightNoWorkList);
        uniqueMember(nameNightWorkList, nameDayWorkList);
    }

    else if(DATESET_NODAYWORK == type){
        nameDayNoWorkList.append(name);
        uniqueMember(nameDayNoWorkList, nameDayWorkList);
    }

    else if(DATESET_NONIGHTWORK == type){
        nameNightNoWorkList.append(name);
        uniqueMember(nameNightNoWorkList, nameNightWorkList);
    }
    else
        QLOG_WARN() << "error worktype:" << type;

    return;
}

myDay &myDay::operator =(const myDay &newObj)
{
    iMonth = newObj.iMonth;
    iDayOfMonth = newObj.iDayOfMonth;
    iDayOfWeek = newObj.iDayOfWeek;
    iRow = newObj.iRow;
    iCol = newObj.iCol;
    iDayType = newObj.iDayType;
    iWorkType = newObj.iWorkType;
    nameDayWorkList = newObj.nameDayWorkList;
    nameNightWorkList = newObj.nameNightWorkList;
    nameDayNoWorkList = newObj.nameDayNoWorkList;
    nameNightNoWorkList = newObj.nameNightNoWorkList;

    return *this;
}
